﻿using Prism.Navigation.Msg;
using Prism.Navigation.Serves;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Prism.Navigation.ViewModels
{
    public class MainViewModel:BindableBase
    {
		private readonly IRegionManager _regionManager;

        private readonly IEventAggregator _eventAggregator;

        public MainViewModel(UserSession userSession,IRegionManager regionManager, IEventAggregator eventAggregator)
        {
            CurrentSession = userSession;
            _regionManager = regionManager;
            //命令
            OpenCommand = new DelegateCommand<string>(open);
            ExitCommand = new DelegateCommand(exit);
            _eventAggregator = eventAggregator;
        }

        private UserSession currentSession;

        public UserSession CurrentSession
        {
			get { return currentSession; }
			set { currentSession = value; }
		}


        public DelegateCommand<string> OpenCommand { get; set; }

        void open(string view)
        {
            _regionManager.Regions["MainContent"].RequestNavigate(view);
        }
        public DelegateCommand ExitCommand { get; set; }

        void exit()
        {
            _eventAggregator.GetEvent<LoginOutMessage>().Publish(currentSession.CurrentUser);
        }

    }
}
